import AutoChart from '@/components/Echarts/AutoChart';
import { graphic } from 'echarts'
// @ts-ignore
import { medicineGrass } from '@/services/api';
import { BorderBox1 } from '@jiaminghi/data-view-react';
import { useEffect } from 'react';
import { useImmer } from 'use-immer';
import './Chart4.less';

const ColumnCharts: React.FC = () => {
  const [options, setOptions] = useImmer({
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'shadow', // 'shadow' as default; can also be 'line' or 'shadow'
      },
    },
    grid: {
      top: '4%',
      left: '7%',
      right: '7%',
      bottom: '7%',
      containLabel: true,
    },
    xAxis: {
      data: [],
      axisLabel: {
        inside: true,
        color: '#fff',
      },
      axisTick: {
        show: true,
      },
      axisLine: {
        show: true,
      },
      z: 10,
    },
    yAxis: {
      axisLine: {
        show: false,
      },
      axisTick: {
        show: false,
      },
      axisLabel: {
        color: '#999',
      },
    },
    dataZoom: [
      {
        type: 'inside',
      },
    ],
    series: [
      {
        type: 'bar',
        showBackground: true,
        itemStyle: {
          color: new graphic.LinearGradient(0, 0, 0, 1, [
            { offset: 0, color: '#83bff6' },
            { offset: 0.5, color: '#188df0' },
            { offset: 1, color: '#188df0' },
          ]),
          borderRadius: [40, 40, 0, 0],
        },
        emphasis: {
          itemStyle: {
            color: new graphic.LinearGradient(0, 0, 0, 1, [
              { offset: 0, color: '#2378f7' },
              { offset: 0.7, color: '#2378f7' },
              { offset: 1, color: '#83bff6' },
            ]),
          },
        },
        data: [],
      },
    ],
  });

  useEffect(() => {
    medicineGrass().then((res) => {
      setOptions((draft) => {
        draft.xAxis.data = res.data.map((i) => i.name);
        draft.series[0].data = res.data.map((i) => Number(i.value));
      });
    });
  }, []);
  return (
    <>
      <div className="'marginb-10">
        <BorderBox1 color={['#396993', '#396993']}>
          <div className="echart_title">
            <div>中药原材料统计</div>
          </div>
          <div className="chart4_height padding-5">
            <AutoChart option={options as any}></AutoChart>
          </div>
        </BorderBox1>
      </div>
    </>
  );
};
export default ColumnCharts;
